"""
Case Type   : 服务端工具
Case Name   : 设置文件系统配置
Create At   : 2020/11/22
Owner       : opentestcase002
Description :
    设置文件系统配置
Expect      :
    设置成功
History     :
    2022-12-1 opentestcase039 优化用例，修改检查断言
"""

import unittest
from yat.test import Node
from yat.test import macro
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger

logger = Logger()


class Tools(unittest.TestCase):
    def setUp(self):
        logger.info('--------------Opengauss_Function_Tools_gs_checkos_Case0026start-------------------')
        self.rootNode = Node('default')
        self.Constant = Constant()

    def test_server_tools(self):
        logger.info('------------------root用户设置文件系统配置------------------')
        checkos_cmd = f'''
                            source {macro.DB_ENV_PATH}
                            gs_checkos -i  B2
                            '''
        logger.info(checkos_cmd)
        msg = self.rootNode.sh(checkos_cmd).result()
        logger.info(msg)
        logger.info('--------------解析执行结果---------------')
        str_1 = msg.split('\n')
        logger.info(str_1)
        if len(str_1) > 2:
            str_list = str_1[1].split(':')
            logger.info(str_list)
            logger.info('--------------校验结果---------------')
            self.assertEqual(len(str_list), 2, '结果验证失败1')
            self.assertEqual(str_list[0].strip(), 'B2. [ Set file system configuration value ]', '结果验证失败3')
            logger.info(str_list[0].strip())
            i = str_list[1].strip()
            self.assertTrue(i in ['Normal', 'Warning', 'Abnormal'], '状态返回错误')
        else:
            raise Exception("解析结果异常")

    def tearDown(self):
        logger.info('--------------无需清理环境-------------------')
        logger.info('------------------Opengauss_Function_Tools_gs_checkos_Case0026finish------------------')